package com.gitee.androidgoodies.batterylog;

import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import androidx.appcompat.app.AlertDialog;

public class BatteryLogConfigUtils {
    
    public static final String TAG = "BatteryLogConfigUtils";
    public static boolean DEBUG = BuildConfig.DEBUG;
    private static final String APP_SPNAME = "BatteryLogConfigUtils";
    private static final String IS_KEEP_RECORDSERVICE = "IsKeepRecordService";
    private static final String IS_LINE_NUM_ENABLE = "IsLineNumEnable";
    private static final String LINE_NUM = "LineNum";
    
    static boolean getConfigIsKeepRecordService(Context context){
        LogUtils.d(TAG, "context.getApplicationContext() is " + context.getApplicationContext());
        SharedPreferences sp = context.getApplicationContext().getSharedPreferences(APP_SPNAME, Context.MODE_PRIVATE);
        return sp.getBoolean(IS_KEEP_RECORDSERVICE, false);
    }
    
    static void setConfigIsKeepRecordService(Context context, boolean isRunRecordService){
        LogUtils.d(TAG, "context.getApplicationContext() is " + context.getApplicationContext());
        SharedPreferences sp = context.getApplicationContext().getSharedPreferences(APP_SPNAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(IS_KEEP_RECORDSERVICE, isRunRecordService);
        editor.commit();
    }
    
    static int getConfigLineNum(Context context){
        SharedPreferences sp = context.getApplicationContext().getSharedPreferences(APP_SPNAME, Context.MODE_PRIVATE);
        return sp.getInt(LINE_NUM, 100);
    }

    static void setConfigLineNum(Context context, int nLineNum){
        SharedPreferences sp = context.getApplicationContext().getSharedPreferences(APP_SPNAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt(LINE_NUM, nLineNum);
        editor.commit();
    }
    
    static boolean getConfigIsLineNumEnable(Context context){
        SharedPreferences sp = context.getApplicationContext().getSharedPreferences(APP_SPNAME, Context.MODE_PRIVATE);
        return sp.getBoolean(IS_LINE_NUM_ENABLE, true);
    }

    static void setConfigIsLineNumEnable(Context context, boolean isLineNumEnable){
        SharedPreferences sp = context.getApplicationContext().getSharedPreferences(APP_SPNAME, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(IS_LINE_NUM_ENABLE, isLineNumEnable);
        editor.commit();
    }
}
